package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.User;
import com.indusfo.spc.service.UserService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 类说明:
 *
 * @author Hewb
 *
 * @version 创建时间：2018年12月6日 上午11:12:58
 */
@Controller
public class LoginController {
    /**
     * 用户登陆接口
     *
     * @Title: LoginController
     * @param user
     * @return
     */

    @Resource
    private UserService userService;


    @RequestMapping("doLogin")
    @ResponseBody
    public JSONObject login(User user, HttpServletRequest request) {
        JSONObject json =  userService.loginUser(user);
        request.getSession().setAttribute("user", json);
        return  json;
    }

    /**
     * 退出当前用户
     *
     * @Title: LoginController
     * @param session
     * @return
     */
    @RequestMapping("logOut")
    @ResponseBody
    public JSONObject loginout(HttpSession session) {
//        try {
//            Subject subject = SecurityUtils.getSubject();
//            subject.logout();
//        } catch (Exception e) {
//            e.getMessage();
//        }

        return JSONObject.oK();
    }


    /**
     * @Method treeRole
     * @Author 熊冰
     * @Version  1.0
     * @Description
     * @param lRoleId
     * @Return com.indusfo.spc.vo.JSONObject
     * @Exception  角色  权限树
     * @Date 2019/9/2 8:57
     */

    @RequestMapping("treeRole")
    @ResponseBody
    public JSONObject treeRole(Integer lRoleId) {
        JSONObject json =  userService.treeRole(lRoleId);
        return  json;
    }
    @RequestMapping("treeMenu")
    @ResponseBody
    public JSONObject treeMenu(Integer lUserId) {
        JSONObject json =  userService.treeMenu(lUserId);
        return  json;
    }

    /**
     * @Method arrayRole
     * @Author 熊冰
     * @Version  1.0
     * @Description
     * @param lRoleId
     * @Return com.indusfo.spc.vo.JSONObject
     * @Exception 角色  权限数组
     * @Date 2019/9/2 8:58
     */
    @RequestMapping("arrayRole")
    @ResponseBody
    public JSONObject arrayRole(Integer lRoleId) {
        JSONObject json =  userService.arrayRole(lRoleId);

        return  json;
    }
    @RequestMapping("arrayMenu")
    @ResponseBody
    public JSONObject arrayMenu(Integer lUserId) {
        JSONObject json =  userService.arrayMenu(lUserId);

        return  json;
    }

    /**
     * @Method listRole
     * @Author 熊冰
     * @Version  1.0
     * @Description
     * @param lRoleId
     * @Return com.indusfo.spc.vo.JSONObject
     * @Exception 角色  权限列表
     * @Date 2019/9/2 8:58
     */
    @RequestMapping("listRole")
    @ResponseBody
    public JSONObject listRole(Integer lRoleId) {
        JSONObject json =  userService.listRole(lRoleId);
        return  json;

    }
    @RequestMapping("listMenu")
    @ResponseBody
    public JSONObject listMenu(Integer lUserId) {
        JSONObject json =  userService.listMenu(lUserId);
        return  json;

    }
}
